<template>
  <div class="app-container">

    <!--  列表  -->
    <el-table v-loading="loading" :data="extractTurntableList" >
      <el-table-column class-name="small-padding fixed-width" label="提取转盘编号" align="center" prop="extractTurntableNo" fixed="left">
        <template slot-scope="scope">
          <span>{{ getTurntableName(scope.row.extractTurntableNo) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="始发地-目的地" align="center" prop="origin" >
        <template slot-scope="scope">
          <span>{{ scope.row.origin + '-' + scope.row.destination}}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="small-padding fixed-width" label="航班号" align="center" prop="flightNo" >
      </el-table-column>
      <el-table-column label="卸货状态" align="center" prop="unloadStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.unload_status" :value="scope.row.unloadStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  fixed="right">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--          >修改</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <!-- 添加或修改航班对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="航班号" prop="flightNo">
          <el-select v-model="form.flightNo" clearable style="width: 228px">
            <el-option
              v-for="item in form.flightNoList"
              :key="item.key"
              :label="item.key"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExtractTurntable, getExtractTurntable, updateExtractTurntable } from "@/api/ground/extractTurntable";

export default {
  name: "ExtractTurntable",
  dicts: ['unload_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提取转盘表格数据
      extractTurntableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        extractTurntableNo:'',
        flightNo: '',
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        flightNo: [
          { required: true, message: "航班不能为空", trigger: "change" }
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  computed:{
  },
  methods: {

    /** 查询提取转盘列表 */
    getList() {
      this.loading = true;
      listExtractTurntable(this.queryParams).then(response => {
        this.extractTurntableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.form= {};
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryIsTransfer = '';
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const extractTurntableId = row.extractTurntableId
      getExtractTurntable(extractTurntableId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改提取转盘信息";
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.extractTurntableId != undefined) {
            updateExtractTurntable(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    //获取仓库编号
    getTurntableName(val){
      if(val == 1){
        return "A转盘";
      }else if(val == 2){
        return "B转盘";
      }
    },

  }
};
</script>

<style lang="scss" scoped>

</style>
